package org.yu.team2023.flashdays.data;

import net.minecraft.advancements.CriterionTriggerInstance;
import net.minecraft.data.PackOutput;
import net.minecraft.data.recipes.*;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.world.item.Items;
import net.minecraft.world.item.crafting.Ingredient;
import net.minecraftforge.common.crafting.IShapedRecipe;
import net.minecraftforge.common.crafting.PartialNBTIngredient;
import org.yu.team2023.flashdays.ModBlockEntities;
import org.yu.team2023.flashdays.ModItems;
import org.yu.team2023.flashdays.TreasureQuality;
import org.yu.team2023.flashdays.TreasureSets;

import java.util.function.Consumer;

public class FDRecipeGenerator extends RecipeProvider {
    public FDRecipeGenerator(PackOutput pOutput) {
        super(pOutput);
    }

    @Override
    protected void buildRecipes(Consumer<FinishedRecipe> pWriter) {
        ShapedRecipeBuilder.shaped(RecipeCategory.BUILDING_BLOCKS, ModBlockEntities.Blocks.TREASURE_UPGRADE.get()).pattern("A A").pattern(" B ").define('A', Items.DIAMOND).define('B', Items.EMERALD).group("treasure_upgrade").unlockedBy("hasDiamond", has(Items.DIAMOND)).save(pWriter);
        {
          var d0=new CompoundTag();
            {
                var dataCommon = new CompoundTag();
                dataCommon.putString("Quality", "COMMON");
                d0.put("TreasureSets", dataCommon);
            }
            var d1=new CompoundTag();
            {
                var dataUncommon = new CompoundTag();
                dataUncommon.putString("Quality", "UNCOMMON");
                d1.put("TreasureSets", dataUncommon);
            }
            var d2=new CompoundTag();

            {
                var dataRare = new CompoundTag();
                dataRare.putString("Quality", "RARE");
                d2.put("TreasureSets", dataRare);
            }
            var d3=new CompoundTag();

            {
                var dataEpic = new CompoundTag();
                dataEpic.putString("Quality", "EPIC");
                d3.put("TreasureSets", dataEpic);
            }
            int index = 0;
            for (TreasureSets value : TreasureSets.TREASURE_SETS_MAP.values()) {
                ShapelessRecipeBuilder.shapeless(RecipeCategory.COMBAT, ModItems.UPGRADE_SMALL.get()).unlockedBy("unlock" + index, has(Items.STRING)).requires(PartialNBTIngredient.of(value.getTreasure1().get(), d0)).save(pWriter, "flashdays:rec_" + index++);
                ShapelessRecipeBuilder.shapeless(RecipeCategory.COMBAT, ModItems.UPGRADE_SMALL.get()).unlockedBy("unlock" + index, has(Items.STRING)).requires(PartialNBTIngredient.of(value.getTreasure2().get(), d0)).save(pWriter, "flashdays:rec_" + index++);
                ShapelessRecipeBuilder.shapeless(RecipeCategory.COMBAT, ModItems.UPGRADE_SMALL.get()).unlockedBy("unlock" + index, has(Items.STRING)).requires(PartialNBTIngredient.of(value.getTreasure3().get(), d0)).save(pWriter, "flashdays:rec_" + index++);
                ShapelessRecipeBuilder.shapeless(RecipeCategory.COMBAT, ModItems.UPGRADE_SMALL.get()).unlockedBy("unlock" + index, has(Items.STRING)).requires(PartialNBTIngredient.of(value.getTreasure4().get(), d0)).save(pWriter, "flashdays:rec_" + index++);

                ShapelessRecipeBuilder.shapeless(RecipeCategory.COMBAT, ModItems.UPGRADE_SMALL.get(),4).unlockedBy("unlock" + index, has(Items.STRING)).requires(PartialNBTIngredient.of(value.getTreasure1().get(), d1)).save(pWriter, "flashdays:rec_" + index++);
                ShapelessRecipeBuilder.shapeless(RecipeCategory.COMBAT, ModItems.UPGRADE_SMALL.get(),4).unlockedBy("unlock" + index, has(Items.STRING)).requires(PartialNBTIngredient.of(value.getTreasure2().get(), d1)).save(pWriter, "flashdays:rec_" + index++);
                ShapelessRecipeBuilder.shapeless(RecipeCategory.COMBAT, ModItems.UPGRADE_SMALL.get(),4).unlockedBy("unlock" + index, has(Items.STRING)).requires(PartialNBTIngredient.of(value.getTreasure3().get(), d1)).save(pWriter, "flashdays:rec_" + index++);
                ShapelessRecipeBuilder.shapeless(RecipeCategory.COMBAT, ModItems.UPGRADE_SMALL.get(),4).unlockedBy("unlock" + index, has(Items.STRING)).requires(PartialNBTIngredient.of(value.getTreasure4().get(), d1)).save(pWriter, "flashdays:rec_" + index++);

                ShapelessRecipeBuilder.shapeless(RecipeCategory.COMBAT, ModItems.UPGRADE_MID.get(),2).unlockedBy("unlock" + index, has(Items.STRING)).requires(PartialNBTIngredient.of(value.getTreasure1().get(), d2)).save(pWriter, "flashdays:rec_" + index++);
                ShapelessRecipeBuilder.shapeless(RecipeCategory.COMBAT, ModItems.UPGRADE_MID.get(),2).unlockedBy("unlock" + index, has(Items.STRING)).requires(PartialNBTIngredient.of(value.getTreasure2().get(), d2)).save(pWriter, "flashdays:rec_" + index++);
                ShapelessRecipeBuilder.shapeless(RecipeCategory.COMBAT, ModItems.UPGRADE_MID.get(),2).unlockedBy("unlock" + index, has(Items.STRING)).requires(PartialNBTIngredient.of(value.getTreasure3().get(), d2)).save(pWriter, "flashdays:rec_" + index++);
                ShapelessRecipeBuilder.shapeless(RecipeCategory.COMBAT, ModItems.UPGRADE_MID.get(),2).unlockedBy("unlock" + index, has(Items.STRING)).requires(PartialNBTIngredient.of(value.getTreasure4().get(), d2)).save(pWriter, "flashdays:rec_" + index++);

                ShapelessRecipeBuilder.shapeless(RecipeCategory.COMBAT, ModItems.UPGRADE_BIG.get()).unlockedBy("unlock" + index, has(Items.STRING)).requires(PartialNBTIngredient.of(value.getTreasure1().get(), d3)).save(pWriter, "flashdays:rec_" + index++);
                ShapelessRecipeBuilder.shapeless(RecipeCategory.COMBAT, ModItems.UPGRADE_BIG.get()).unlockedBy("unlock" + index, has(Items.STRING)).requires(PartialNBTIngredient.of(value.getTreasure2().get(), d3)).save(pWriter, "flashdays:rec_" + index++);
                ShapelessRecipeBuilder.shapeless(RecipeCategory.COMBAT, ModItems.UPGRADE_BIG.get()).unlockedBy("unlock" + index, has(Items.STRING)).requires(PartialNBTIngredient.of(value.getTreasure3().get(), d3)).save(pWriter, "flashdays:rec_" + index++);
                ShapelessRecipeBuilder.shapeless(RecipeCategory.COMBAT, ModItems.UPGRADE_BIG.get()).unlockedBy("unlock" + index, has(Items.STRING)).requires(PartialNBTIngredient.of(value.getTreasure4().get(), d3)).save(pWriter, "flashdays:rec_" + index++);

                ShapelessRecipeBuilder.shapeless(RecipeCategory.COMBAT, ModItems.UPGRADE_SMALL.get()).unlockedBy("unlock" + index, has(Items.STRING)).requires(Ingredient.of(value.getUnidentifieds().get(TreasureQuality.COMMON).get())).save(pWriter, "flashdays:rec_" + index++);
                ShapelessRecipeBuilder.shapeless(RecipeCategory.COMBAT, ModItems.UPGRADE_SMALL.get(),4).unlockedBy("unlock" + index, has(Items.STRING)).requires(Ingredient.of(value.getUnidentifieds().get(TreasureQuality.UNCOMMON).get())).save(pWriter, "flashdays:rec_" + index++);
                ShapelessRecipeBuilder.shapeless(RecipeCategory.COMBAT, ModItems.UPGRADE_MID.get(),2).unlockedBy("unlock" + index, has(Items.STRING)).requires(Ingredient.of(value.getUnidentifieds().get(TreasureQuality.RARE).get())).save(pWriter, "flashdays:rec_" + index++);
                ShapelessRecipeBuilder.shapeless(RecipeCategory.COMBAT, ModItems.UPGRADE_BIG.get()).unlockedBy("unlock" + index, has(Items.STRING)).requires(Ingredient.of(value.getUnidentifieds().get(TreasureQuality.EPIC).get())).save(pWriter, "flashdays:rec_" + index++);
            }
            ShapelessRecipeBuilder.shapeless(RecipeCategory.COMBAT,ModItems.UPGRADE_MID.get())
                    .unlockedBy("has__0",has(Items.STRING))
                    .requires(ModItems.UPGRADE_SMALL.get(),4)
                    .save(pWriter);
            ShapelessRecipeBuilder.shapeless(RecipeCategory.COMBAT,ModItems.UPGRADE_BIG.get())
                    .unlockedBy("has__1",has(Items.STRING))
                    .requires(ModItems.UPGRADE_MID.get(),4)
                    .save(pWriter);
        }


    }
}
